home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / READKEY2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  6KB  |  143 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from encrypted registration-key file, using "embedded"   *)
  5. (* encryption-code strings.                                           *)
  6. (*                                                                    *)
  7. (* NOTE: Before you can compile this program, you must first          *)
  8. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  9. (*       the two "random" encryption-code binary data files. Then     *)
  10. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  11. (*       these two binary data files to "object" format files.        *)
  12. (**********************************************************************)
  13.  
  14. program Read_FlxKey_Demo2;
  15. uses
  16.   Crt,
  17.   FlxKey;
  18.  
  19. type
  20.               (* 20 character string-pointer definition.              *)
  21.   post_20 = ^st_20;
  22.  
  23. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  24.               (* the difference in days between the current date and  *)
  25.               (* the date encrypted into the registration-key file.   *)
  26.   DaysOld,
  27.  
  28.               (* This variable is used to check for errors returned   *)
  29.               (* by ReadFlxKey routine.                               *)
  30.   ErrorCode  : word;
  31.  
  32.               (* Encryption-code string-pointers, used to decrypt the *)
  33.               (* data in the encrypted registration-key file.         *)
  34.   Ecode1Ptr,
  35.   Ecode2Ptr  : post_20;
  36.  
  37.               (* This is the full path/filename of the encrypted      *)
  38.               (* registration-key file to be decrypted.               *)
  39.   RegKeyName : st_79;
  40.  
  41.               (* Record variable to hold the data decrypted from the  *)
  42.               (* encrypted registration-key file.                     *)
  43.   TempKeyRec : rc_Flx;
  44.  
  45.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  46.  
  47.               (* "Fake" procedure that contains first encryption-code *)
  48.               (* string.                                              *)
  49.   procedure Ecode1Data; external;
  50.   {$L ECODE1.OBJ}
  51.  
  52.               (* "Fake" procedure that contains second encryption-    *)
  53.               (* code string.                                         *)
  54.   procedure Ecode2Data; external;
  55.   {$L ECODE2.OBJ}
  56.  
  57.   {$F-}       (* Turn off "FAR" declaration.                          *)
  58.  
  59.               (* Main program execution block.                        *)
  60. BEGIN
  61.               (* Initialize the encryption-code string pointers to    *)
  62.               (* their data.                                          *)
  63.   Ecode1ptr := addr(Ecode1Data);
  64.   Ecode2ptr := addr(Ecode2Data);
  65.  
  66.               (* Clear the temporary key-record variable.             *)
  67.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  68.  
  69.               (* Full path/filename for the encrypted registration-   *)
  70.               (* key file to be decrypted.                            *)
  71.   RegKeyName := 'DEMO2.KEY';
  72.  
  73.               (* Decrypt the registration-key file, and retreive it's *)
  74.               (* data.                                                *)
  75.               (* NOTE: A 10 second delay and message are present in   *)
  76.               (*       the un-registered copy of the FlxKey unit.     *)
  77.   ReadFlxKey(Ecode1Ptr^, Ecode2Ptr^, RegKeyName, TempKeyRec, DaysOld,
  78.              ErrorCode);
  79.  
  80.               (* Clear the screen.                                    *)
  81.   clrscr;
  82.   writeln;
  83.  
  84.               (* Check for errors.                                    *)
  85.   if (ErrorCode <> 0) then
  86.     case (ErrorCode AND $FF) of
  87.        1 : writeln(' Error! One or more encryption-codes is blank.');
  88.        2 : writeln(' Error! Filename for registration-key file is blank.');
  89.        3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  90.                    'buffer.');
  91.        4 : writeln(' BlocWrite error.');
  92.        5 : writeln(' BlockRead error.');
  93.        6 : writeln(' Date error. PC''s system date pre-dates ' +
  94.                    'registration-key date.');
  95.        7 : writeln(' Registration-key is corrupt.');
  96.  
  97.               (* I/O error!                                           *)
  98.       16 : begin
  99.              writeln(' I/O error = ', (ErrorCode shr 8));
  100.  
  101.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  102.               (* as there are many types of errors to check for.      *)
  103.              case (ErrorCode shr 8) of
  104.                  2 : writeln(' File not found.');
  105.                  3 : writeln(' Path not found.');
  106.                  4 : writeln(' Too many files open.');
  107.                  5 : writeln(' File access denied.');
  108.                100 : writeln(' Disk read error.');
  109.                103 : writeln(' File not open')
  110.              end  (* case (ErrorCode shr 8) of                        *)
  111.            end
  112.     end       (* case (ErrorCode AND $FF) of                          *)
  113.   else
  114.               (* Else NO errors occurred.                             *)
  115.     begin
  116.               (* Display the decrypted registration-key data.         *)
  117.       writeln('Key is ', DaysOld, ' days old');
  118.       writeln;
  119.       with TempKeyRec do
  120.         begin
  121.           writeln(' FirstName    = ', FirstName);
  122.           writeln(' LastName     = ', LastName);
  123.           writeln(' Address1     = ', Address1);
  124.           writeln(' Address2     = ', Address2);
  125.           writeln(' Address3     = ', Address3);
  126.           writeln(' AppName      = ', AppName);
  127.           writeln(' Version      = ', Version);
  128.           writeln(' Serial Num   = ', Serial);
  129.  
  130.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  131.               (* can be used to manipulate "packed date" data.        *)
  132.           writeln(' Packed Date  = ', Date);
  133.  
  134.           writeln(' Access Level = ', Access);
  135.  
  136.           writeln(' MiscData     = ', MiscData)
  137.  
  138.         end
  139.     end
  140. END.
  141.  
  142.  
  143.